<template>
  <div class="translate-container">
    <div class="row">
      <div class="label">自动关闭</div>
      <el-switch v-model="appConfigCurrent.auto_close" />
    </div>
    <div class="actions">
      <el-button type="primary" @click="save">保存</el-button>
      <el-button @click="reset">重置</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { useAppConfig } from "@/hooks/useAppConfig";
import { ElMessage } from "element-plus";

const { appConfigCurrent, updateConfig, setConfig } = useAppConfig("translate");

async function save() {
  try {
    await updateConfig();
    ElMessage.success("保存成功");
  } catch (error) {
    ElMessage.error("保存失败: " + error);
  }
}
async function reset() {
  try {
    await setConfig({
      auto_close: false,
    });
    ElMessage.success("重置成功");
  } catch (error) {
    ElMessage.error("重置失败: " + error);
  }
}
</script>

<style scoped lang="scss">
.translate-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  .row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
  }
}
</style>
